﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QuestPrototype.Menus;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
namespace QuestPrototype.Screen_Manager.Screens.Menus
{
    class MainMenu : BaseScreen
    {
        private List<MenuEntry> Entries = new List<MenuEntry>();
        private int MenuSelect = 0;

        private Vector2 MenuSize = new Vector2(250, 160);
        private Vector2 MenuPos = new Vector2(130, 280);

        public override void HandleInput()
        {
            // MENU UP
            if (Input.KeyPressed(Keys.Up))
            {
                do
                {
                    MenuSelect -= 1;
                    if (MenuSelect < 0)
                    {
                        MenuSelect = Entries.Count - 1;
                    }


                } while (Entries.ElementAt(MenuSelect).Enabled != true);
            }

            // MENU UP
            if (Input.KeyPressed(Keys.Down))
            {
                do
                {
                    MenuSelect += 1;
                    if (MenuSelect > Entries.Count - 1)
                    {
                        MenuSelect = 0;
                    }


                } while (Entries.ElementAt(MenuSelect).Enabled != true);
            }


            //INVOKE MENU ITEM
            if (Input.KeyPressed(Keys.Enter))
            {
                switch (MenuSelect)
                {
                    case 0:
                        Console.WriteLine("You just started a new game!");
                        break;
                    case 1:
                        Console.WriteLine("You continue your adventure.");
                        break;
                    case 2:
                        Console.WriteLine("As a programmer, you have many options!");
                        break;
                    case 3:
                        Console.WriteLine("This game was created by me!");
                        break;

                }
            }


        }
        public MainMenu()
        {
            Name = "MainMenu";
            State = ScreenState.Active;

            // ADD ENTRIES HERE
            AddEntry("New Game", true);
            AddEntry("Continue Game", false);
            AddEntry("Options", true);
            AddEntry("Credits", true);
        }

        public void AddEntry(string text, bool enabled)
        {
            MenuEntry Entry = new MenuEntry();
            Entry.Text = text;
            Entry.Enabled = enabled;
            Entries.Add(Entry);
        }

        public override void Draw()
        {

            Globals.SpriteBatch.Begin();
            // Draw Menu Graphics
            MenuGFX.DrawMenuGFX(new Rectangle((int)MenuPos.X, (int)MenuPos.Y, (int)MenuSize.X, (int)MenuSize.Y), Color.White, true, Globals.SpriteBatch, Textures.Menu1, 0.6);

            // Draw Menu Options
            int MenuY = (int)MenuPos.Y + 20;
            for (int x = 0; x < Entries.Count; x++)
            {
                if (x == MenuSelect)
                {
                    Globals.SpriteBatch.DrawString(Fonts.Georgia_16, Entries.ElementAt(x).Text, new Vector2(MenuPos.X + (MenuSize.X / 2) - Fonts.Georgia_16.MeasureString(Entries.ElementAt(x).Text).X / 2, MenuY), Color.Orange);

                }
                else if (Entries.ElementAt(x).Enabled == true)
                {
                    Globals.SpriteBatch.DrawString(Fonts.Georgia_16, Entries.ElementAt(x).Text, new Vector2(MenuPos.X + (MenuSize.X / 2) - Fonts.Georgia_16.MeasureString(Entries.ElementAt(x).Text).X / 2, MenuY), Color.White);

                }
                else
                {
                    Globals.SpriteBatch.DrawString(Fonts.Georgia_16, Entries.ElementAt(x).Text, new Vector2(MenuPos.X + (MenuSize.X / 2) - Fonts.Georgia_16.MeasureString(Entries.ElementAt(x).Text).X / 2, MenuY), Color.Gray);

                }

                MenuY += 30;
            }
            Globals.SpriteBatch.End();
        }
    }
}
